package com.jh.readme.iu.fragment.news.common;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.jh.readme.R;
import com.jh.readme.iu.fragment.news.entity.NewsEntity;
import com.jh.readme.iu.fragment.newslist.NewsListFragment;
import com.jh.tools.base.BaseFragment;

import java.util.List;

/**
 * Created by huangzx on 2015/8/27.
 */
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {

    final int PAGE_COUNT = 3;
    private List<NewsEntity> mNewsEntitys;
    private Context context;

    public SimpleFragmentPagerAdapter(FragmentManager fm,List<NewsEntity> newsEntitys,Context context) {
        super(fm);
        this.context = context;
        this.mNewsEntitys=newsEntitys;
    }

    @Override
    public Fragment getItem(int position) {
        return NewsListFragment.newInstance(mNewsEntitys.get(position).newsId,mNewsEntitys.get(position).newsType,position);
    }

    @Override
    public int getCount() {
        return null!=mNewsEntitys?mNewsEntitys.size():0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        //第一次的代码
        //return tabTitles[position];
        //第二次的代码
        /**
         Drawable image = context.getResources().getDrawable(imageResId[position]);
         image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
         SpannableString sb = new SpannableString(" " + tabTitles[position]);
         ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
         sb.setSpan(imageSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
         return sb;*/


        return mNewsEntitys.get(position).tabNewsName;
    }

}
